<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="20" :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="168px"
        >
          <el-form-item label="获得积分或荣誉值时间：" prop="time">
            <el-date-picker
              v-model="time"
              align="right"
              type="daterange"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="change"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item prop="statisticType">
            <el-select v-model="queryParams.examineType" placeholder="统计类型" clearable>
              <el-option
                v-for="dict in dict.type.examine_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">统计</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            <el-button
              type="danger"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"

            >导出
            </el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="analysisList" style="margin-bottom: 30px" @sort-change="sortChange">
          <el-table-column align="center" label="排名" prop="rank" width="50"/>
          <el-table-column align="center" label="公司名称" prop="deptName"/>
          <el-table-column align="center" label="获得总积分" prop="totalScore" sortable="custom"/>
          <el-table-column align="center" label="获得总荣誉值" prop="totalHonorScore" sortable="custom"/>
          <el-table-column align="center" label="人均积分" prop="avgScore" sortable="custom"/>
          <el-table-column align="center" label="人均荣誉值" prop="avgHonor" sortable="custom"/>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {listCompAnalysis} from '@/api/examine/dataAnalysis/api'

export default {
  name: 'companyCourage',
  dicts: ['examine_type'],
  data() {
    return {
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      analysisList: [],
      time: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        examineType: null,
        beginTime: null,
        endTime: null,
        sortPropertyName: '',
        sortType: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询数据分析列表 */
    getList() {
      this.loading = true
      listCompAnalysis(this.queryParams).then(response => {
        this.analysisList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    sortChange(column) {
      this.queryParams.sortPropertyName = column.prop
      this.queryParams.sortType = column.order
      this.getList()
    },
    change(value) {
      if (value == null) {
        this.time = value
        this.queryParams.beginTime = value
        this.queryParams.endTime = value
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if (this.time) {
        this.queryParams.beginTime = this.time[0]
        this.queryParams.endTime = this.time[1]
      }
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.data = null
      this.time = null
      this.queryParams.examineType = null
      this.queryParams.beginTime = null
      this.queryParams.endTime = null
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('examine/analysis/companyExport', {
        ...this.queryParams
      }, `子公司激励排名.xlsx`)
    }
  }
}
</script>
